import 'dart:ui' as ui show Image;

import 'package:flutter/cupertino.dart';
import 'package:flutter/rendering.dart';

/// 自定义Element
class PageElement extends SingleChildRenderObjectElement {
  PageElement(SingleChildRenderObjectWidget widget) : super(widget);
}

/// 自定义RenderObject，摆脱Debug模式才能用的 [DebugCreator] 限制
class PageRenderObject extends RenderProxyBox {
  PageRenderObject(this.element);
  PageElement element;

  Future<ui.Image?> toImage({double pixelRatio = 1.0}) {
    if (layer is! OffsetLayer) {
      Future.delayed(const Duration()).then((value) {
        return null;
      });
    }
    var offsetLayer = layer as OffsetLayer;

    return offsetLayer.toImage(Offset.zero & size, pixelRatio: pixelRatio);
  }

  /// for [toImage]
  @override
  bool get isRepaintBoundary => true;
}
